package com.admin.system.runner;

import com.admin.system.modules.quartz.QuartzManage;
import com.admin.system.modules.quartz.entity.QuartzJob;
import com.admin.system.modules.quartz.mapper.QuartzJobMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author /
 */
@Component
@RequiredArgsConstructor
@Slf4j
public class QuartzJobRunner implements ApplicationRunner {

    private final QuartzJobMapper quartzJobMapper;
    private final QuartzManage quartzManage;

    /**
     * 项目启动时重新激活启用的定时任务
     *
     * @param applicationArguments /
     */
    @Override
    public void run(ApplicationArguments applicationArguments) {
        List<QuartzJob> quartzJobs = quartzJobMapper.selectList(Wrappers.<QuartzJob>lambdaQuery().eq(QuartzJob::getIsPause, 0));
        quartzJobs.forEach(quartzManage::addJob);
        log.info("Timing task injection complete");
    }
}
